package me.stone.stanimeclient.page.home

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.youth.banner.adapter.BannerAdapter
import me.stone.stanimeclient.core.model.FanSimpleItem
import me.stone.stanimeclient.databinding.HolderImageTitleBannerBinding
import me.stone.stanimeclient.util.imageFromUrl

class ImageTitleBannerAdapter (
    items: List<FanSimpleItem> = emptyList()
): BannerAdapter<FanSimpleItem, ImageTitleBannerAdapter.ImageTitleHolder>(items) {

    inner class ImageTitleHolder(
        val binding: HolderImageTitleBannerBinding
    ): ViewHolder(binding.root)

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): ImageTitleHolder {
        return ImageTitleHolder(HolderImageTitleBannerBinding.inflate(
            LayoutInflater.from(parent!!.context), parent, false
        ))
    }

    override fun onBindView(
        holder: ImageTitleHolder?,
        data: FanSimpleItem?,
        position: Int,
        size: Int
    ) {
        holder?.binding?.apply {
            data?.let {
                image.imageFromUrl(it.coverUrl)
                title.text = it.title
            }
        }
    }

}